package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.ComnRecentlyUsed;
import com.ruoyi.comn.service.IComnRecentlyUsedService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 最近使用内容Controller
 * 
 * @author ruoyi
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/recentlyUsed")
@Component("recentlyUsed")
public class ComnRecentlyUsedController extends BaseController
{
    @Autowired
    private IComnRecentlyUsedService comnRecentlyUsedService;

    /**
     * 查询最近使用内容列表
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:list")
    @GetMapping("/list")
    public TableDataInfo list(ComnRecentlyUsed comnRecentlyUsed)
    {
        startPage();
        List<ComnRecentlyUsed> list = comnRecentlyUsedService.selectComnRecentlyUsedList(comnRecentlyUsed);
        return getDataTable(list);
    }

    /**
     * 导出最近使用内容列表
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:export")
    @Log(title = "最近使用内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComnRecentlyUsed comnRecentlyUsed) throws IOException
    {
        List<ComnRecentlyUsed> list = comnRecentlyUsedService.selectComnRecentlyUsedList(comnRecentlyUsed);
        ExcelUtil<ComnRecentlyUsed> util = new ExcelUtil<ComnRecentlyUsed>(ComnRecentlyUsed.class);
        util.exportExcel(response, list, "最近使用内容数据");
    }

    /**
     * 获取最近使用内容详细信息
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:query")
    @GetMapping(value = "/{usedUuid}")
    public AjaxResult getInfo(@PathVariable("usedUuid") String usedUuid)
    {
        return AjaxResult.success(comnRecentlyUsedService.selectComnRecentlyUsedByUsedUuid(usedUuid));
    }

    /**
     * 新增最近使用内容
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:add")
    @Log(title = "最近使用内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComnRecentlyUsed comnRecentlyUsed)
    {
        return toAjax(comnRecentlyUsedService.insertComnRecentlyUsed(comnRecentlyUsed));
    }

    /**
     * 修改最近使用内容
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:edit")
    @Log(title = "最近使用内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComnRecentlyUsed comnRecentlyUsed)
    {
        return toAjax(comnRecentlyUsedService.updateComnRecentlyUsed(comnRecentlyUsed));
    }

    /**
     * 删除最近使用内容
     */
    @PreAuthorize(hasPermi = "comn:recentlyUsed:remove")
    @Log(title = "最近使用内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usedUuids}")
    public AjaxResult remove(@PathVariable String[] usedUuids)
    {
        return toAjax(comnRecentlyUsedService.deleteComnRecentlyUsedByUsedUuids(usedUuids));
    }


    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }


}
